﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Caifu.Clients;
using Newtonsoft.Json;

namespace Caifu.WebSite.HQ
{
	public partial class Q : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			Response.Write(All());
		}

		public string All()
		{
			var all = NetValueDailyClient.GetAllNetValueDailys();
			string result = "[";
			string header = "['Category','FundCode','FundName','ReportDate','UnitNetValue','PreviousUnitNetValue','GrowthValue','GrowthRate']";
			result += header;
			foreach (var item in all)
			{
				string temp = ",['{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}']";
				temp = String.Format(temp,
										item.Category,
										item.FundCode,
										item.FundName,
										item.ReportDate.ToString("yyyy-MM-dd"),
										Convert(item.UnitNetValue),
										Convert(item.PreviousUnitNetValue),
										Convert(item.GrowthValue),
										Convert(item.GrowthRate));

				result += temp;
			}
			result += "]";

			return result;
		}

		string Convert(decimal? v)
		{
			return v.HasValue ? v.Value.ToString() : "--";
		}

		public void Single(string code)
		{

		}
	}
}